<?php
class Zendvn_View_Helper_TinyMce extends Zend_View_Helper_Abstract
{
	
	public function tinyMce($name,$value = null, $attribs = null, $options = null){
		
		$jsUrl = SCRIPTS_URL . '/tinymce/tinymce.min.js';
		$tinyPath = SCRIPTS_PATH . '/tinymce';
		$tinyUrl = SCRIPTS_URL . '/tinymce';
		unset($_SESSION['ajaxFile']);	
		$ajaxArrary = array('member'=>true);
		$_SESSION['ajaxFile'] = $ajaxArrary;
		$strAttribs = '';
		if(count($attribs)>0){
			foreach ($attribs as $key => $val){
				$strAttribs .= $key . '="' . $val . '" ';
			}			
		}
		
		$this->view->headScript()->appendFile($jsUrl);
		if($options == null){
			$script = '
				tinymce.init({
				    selector: "#' . $name . '",
				    plugins: [
				        "advlist autolink lists link image charmap print preview anchor",
				        "searchreplace visualblocks code fullscreen",
				        "insertdatetime media table contextmenu paste"
				    ],
				    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
				    
				    image_advtab: true ,
   
				   	external_filemanager_path:"' . $tinyUrl . '/plugins/filemanager/",
				   	filemanager_access_key : "zend_administrator",
				   	filemanager_title:"Responsive Filemanager" ,
				   	external_plugins: { "filemanager" : "' . $tinyUrl . '/plugins/filemanager/plugin.min.js"}
				})';
		}
		
		$this->view->headScript()->appendScript($script);
		$xhtml = '<textarea id="' . $name . '" name="' . $name . '" ' . $strAttribs . ' >'
				  . $value
				   . '</textarea>';
		
		return $xhtml;
	}
}
